package com.lkd.handler;

import com.google.common.base.Strings;
import com.lkd.business.MsgHandler;
import com.lkd.contract.SupplyChannel;
import com.lkd.contract.SupplyContract;
import com.lkd.emq.Topic;
import com.lkd.service.ChannelService;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @Author FJL
 * @Description TODO
 * @Date 2022/8/25 20:53
 **/
@Component
@Topic("TopicConfig.VMS_SUPPLY_TOPIC")
public class SupplyHandler implements MsgHandler {
    @Autowired
    private VendingMachineService vmService; //售货机服务

    @Autowired
    private ChannelService channelService; //货道服务

    @Override
    public void process(String jsonMsg) throws IOException {
        // 将json字符串解析成supplyContract
        SupplyContract supplyContract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);
        // 参数校验
        if(supplyContract==null || Strings.isNullOrEmpty(supplyContract.getInnerCode())) return;

        // 更新货道信息
        List<SupplyChannel> supplyData = supplyContract.getSupplyData();
        channelService.updateChannels(supplyData,supplyContract.getInnerCode());





    }
}
